import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../components/Home.vue'
import ClubIntroduce from '../components/ClubIntroduce.vue'
import ClubDyn from '../components/clubDyn/ClubDyn.vue'
import MyDyn from '../components/person/MyDyn.vue'
import MyHomePage from '../components/person/MyHomePage.vue'
import Editor from '../components/person/Editer.vue'
import Login from '../components/Login.vue'
import ForgetPass from '../components/ForgetPass.vue'
import Register from '../components/Register.vue'
import PersonalData from '../components/person/PersonalData.vue'
import Fans from '../components/person/Fans.vue'
import Artical from '../components/person/Artical.vue'
import Concern from '../components/person/Concern.vue'
import ChangePass from '../components/person/ChangePass.vue'
import SearchResult from '../components/person/SearchResult.vue'
import ArticalRes from '../components/person/ArticalRes.vue'
import UserRes from '../components/person/UserRes.vue'


Vue.use(VueRouter)

const routes = [  
  {
  path: "/",
  redirect:"/login"
  },
  {
    path:"/login",
    component:Login,
  },
  {
    path:"/getPass",
    component:ForgetPass,
  },
  {
    path:"/register",
    component:Register,
  },
  
  {
    path:'/changepass',
    component:ChangePass
  },
  {
    path: '/home',
    component: Home,
    // redirect:'/clubDyn',
    redirect:'/clubInt',
    children:[
      {path:'/clubInt',component:ClubIntroduce},
      {path:'/clubDyn',component:ClubDyn},
      {path:'/myDyn',component:MyDyn},
      // 搜索结果
      {path:'/searchResult',
        component:SearchResult,
        redirect:'/articalRes',
        children:[
          {path:'/articalRes',component:ArticalRes},
          {path:'/userRes',component:UserRes},
        ],

      },
      // 个人主页
      { 
        path:'/myHomePage',
        component:MyHomePage,
        redirect:'/artical',
        children:[
          {path:'/fans',component:Fans},
          {path:'/artical',component:Artical},
          {path:'/concern',component:Concern},
          {path:'/personalData',component:PersonalData},
        ],
      },
      {path:'/editor',component:Editor,},

    ]
  },
]

const router = new VueRouter({
  routes,
  mode:'history'
})
router.beforeEach((to,from,next)=>{
  //    next（）放行， next（'/URL'）强制跳转的路径。||to.path=='/clubDyn'
  if(to.path=='/login'||to.path=='/getPass'||to.path=='/register') return next();//访问路径为登录
  //获取flag
  const flagStr = window.sessionStorage.getItem("flag");//session 取值
  if(!flagStr) return next('/login');//没登录去登陆
  next();
})
export default router
